import axios from "axios";

export default {
  state: {
    positions: [],
  },
  getters: {},
  mutations: {
    getPositionNameById(state, id) {
      let name = "";
      for (let i = 0; i < state.positions.length; i++) {
        if (state.positions[i].id == id) {
          name = state.positions[i].name;
          break;
        }
      }
      return name;
    },
  },
  actions: {
    getPositions(context, data) {
      let url = "/position/get/all";
      let postData = {};
      let config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      axios
        .post(url, postData, config)
        .then((resp) => {
          context.state.positions = resp.data.data;
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
  },
  modules: {},
};
